<?php

error_reporting(0);
$user = addslashes($_POST['user']);

$data = require('./config.php');

$db = new mysqli($data['host'],$data['user'],$data['pass'],$data['dbname']);
if($db->connect_error){
    die("db link fail!");
}
if(empty($user)){
    return json_encode(array('code' =>0,'msg' =>'暂无此账号！'));
}

//构造查询sql语句

$sql = "SELECT * FROM `todo` where user = `{$user}`";
$result = $db->query($sql);

if($result->num_rows>0){
    while($row = $result->fetch_assoc()){
        return json_encode(array('data' =>"{'id':{$row['id']},'title':{$row['title']}}"));
    }
}else {
    return json_encode(array('code' =>0,'msg' =>'暂无数据！'));
}


?>